<?php
require_once("database.php");
require_once '../DTO/DUAN_DTO.php';
class xl_du_an extends database
{
	function danh_sach($vi_tri, $so_luong)
	{
		$vi_tri = intval($vi_tri);
		$so_luong = intval($so_luong);
		$sql = "select * from du_an limit $vi_tri, $so_luong";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}

    function danh_sach_theo_loai($vi_tri, $so_luong, $ma_phieu, $ma_lda)
    {
        $vi_tri = intval($vi_tri);
        $so_luong = intval($so_luong);
        $sql = "SELECT da . *
                FROM du_an da, loai_du_an lda, phieu_dang_ky pdk, loai_phieu lp
                WHERE da.loai_dua_an = lda.ma
                AND pdk.ma_da = da.ma
                AND pdk.loai_phieu = lp.ma
                AND lp.ma = $ma_phieu
                AND lda.ma = $ma_lda
                LIMIT  $vi_tri, $so_luong";
        $this->setQuery($sql);
        return $this->loadAllRow();
    }

    function danh_sach_theo_loai_all($vi_tri, $so_luong, $ma_phieu)
    {
        $vi_tri = intval($vi_tri);
        $so_luong = intval($so_luong);
        $sql = "SELECT da . *
                FROM du_an da, loai_du_an lda, phieu_dang_ky pdk, loai_phieu lp
                WHERE da.loai_dua_an = lda.ma
                AND pdk.ma_da = da.ma
                AND pdk.loai_phieu = lp.ma
                AND lp.ma = $ma_phieu
                LIMIT  $vi_tri, $so_luong";
        $this->setQuery($sql);
        return $this->loadAllRow();
    }

    function xem_chi_tiet($ma)
    {
        $ma = intval($ma);

        $sql = "select * from du_an where ma = '$ma'";
        $this->setQuery($sql);
        return $this->loadRow();
    }

	function so_luong()
	{
		$sql = "select count(*) from du_an";
		$this->setQuery($sql);
		return $this->loadResult();
	}

    function so_luong_theo_loai( $ma_phieu, $ma_lda)
    {
        $sql = "SELECT da . *
                FROM du_an da, loai_du_an lda, phieu_dang_ky pdk, loai_phieu lp
                WHERE da.loai_dua_an = lda.ma
                AND pdk.ma_dn = da.ma
                AND pdk.loai_phieu = lp.ma
                AND lp.ma = $ma_phieu
                AND lda.ma = $ma_lda ";
        $this->setQuery($sql);
        return $this->loadResult();
    }

	function xem($ma)
	{
		$ma = intval($ma);

		$sql = "select * from du_an where ma = '$ma'";
		$this->setQuery($sql);
		return $this->loadRow();
	}

	function xoa($ma)
	{
		$ma = intval($ma);

		$sql = "delete from du_an where ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function them(DUAN_DTO $info)
	{


        $info->ten_du_an = stripslashes($info->ten_du_an);
		$info->ten_du_an = addslashes($info->ten_du_an);

        $info->dia_chi = stripslashes($info->dia_chi);
        $info->dia_chi = addslashes($info->dia_chi);

        $info->von_dau_tu = stripslashes($info->von_dau_tu);
        $info->von_dau_tu = addslashes($info->von_dau_tu);

        $info->loai_dua_an = stripslashes($info->loai_dua_an);
        $info->loai_dua_an = addslashes($info->loai_dua_an);

        $info->thong_tin_chi_tiet = stripslashes($info->thong_tin_chi_tiet);
        $info->thong_tin_chi_tiet = addslashes($info->thong_tin_chi_tiet);


		$sql = "INSERT INTO du_an VALUES (  '$info->ten_du_an',
                                            '$info->dia_chi  ',
                                             '$info->von_dau_tu' ,
                                             '$info->loai_dua_an' ,
                                             '$info->thong_tin_chi_tiet' ,
                                             '$info->tinh_trang_cap_phep' ,
                                             '$info->ngay_cap_phep ' ,
                                             '$info->thoi_gian_du_kien_cp' ,
                                             0
                                           )";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat($ma, $ho_ten, $ngay_sinh, $gioi_tinh, $dia_chi, $dien_thoai, $email, $vi_tri_ung_tuyen, $tu_gioi_thieu, $trang_thai)
	{
		$ma = intval($ma);
		$ho_ten = stripslashes($ho_ten);
		$ho_ten = addslashes($ho_ten);
		$dia_chi = stripslashes($dia_chi);
		$dia_chi = addslashes($dia_chi);
		$dien_thoai = stripslashes($dien_thoai);
		$dien_thoai = addslashes($dien_thoai);
		$email = stripslashes($email);
		$email = addslashes($email);
		$vi_tri_ung_tuyen = stripslashes($vi_tri_ung_tuyen);
		$vi_tri_ung_tuyen = addslashes($vi_tri_ung_tuyen);
		$tu_gioi_thieu = stripslashes($tu_gioi_thieu);
		$tu_gioi_thieu = addslashes($tu_gioi_thieu);

		$sql ="UPDATE du_an SET ho_ten= '$ho_ten', ngay_sinh= '$ngay_sinh', gioi_tinh= '$gioi_tinh', dia_chi= '$dia_chi', dien_thoai= '$dien_thoai', email= '$email', vi_tri_ung_tuyen= '$vi_tri_ung_tuyen', tu_gioi_thieu= '$tu_gioi_thieu', trang_thai= '$trang_thai' WHERE ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function tim_kiem ($tu_khoa)
	{
		//$sql = "select * from du_an where	$ho_ten like %tu_khoa% or 	$dia_chi like %tu_khoa% or 	$dien_thoai like %tu_khoa% or 	$email like %tu_khoa% or 	$vi_tri_ung_tuyen like %tu_khoa% or 	$tu_gioi_thieu like %tu_khoa%";
		//$this->setQuery($sql);
		return $this->loadAllRow();	
	}
 }
?>